package com.base.cn.platform.os.controller.user.account;

import com.base.cn.platform.os.common.controller.BaseController;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.entity.user.account.CusUserCashAccount;
import com.base.cn.platform.os.service.user.account.CusUserCashAccountBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 用户提现账户Controller
 *
 * @author s.li
 * @date 2018/12/01
 */
@RestController
@RequestMapping("/manage/account")
public class CusUserCashAccountController extends BaseController {

    @Autowired
    private CusUserCashAccountBiz cusUserCashAccountBiz;

    /**
     * 保存用户提现账户记录
     * @param userCashAccount
     * @return Map<String,Object>
     */
    @RequestMapping("/saveUserCashAccount")
    public Map<String,Object> saveUserCashAccount(@RequestBody CusUserCashAccount userCashAccount){
        if(StringUtils.isEmpty(userCashAccount.getRealName())){
            return ResultUtil.ERROR("请填写账户真实姓名");
        }
        if(userCashAccount.getAccountType().intValue()==1){
            if(StringUtils.isEmpty(userCashAccount.getAccount())){
                return ResultUtil.ERROR("请填写支付宝账号");
            }
        }
        cusUserCashAccountBiz.saveUserCashAccount(userCashAccount);
        return ResultUtil.SUCCESS();
    }

    /**
     * 查询用户的提现账户数据列表
     * @param userId 用户ID
     * @return List<CusUserCashAccount>
     */
    @RequestMapping("/findUserCashAccount")
    public Map<Integer,CusUserCashAccount> findUserCashAccount(@RequestParam("userId") BigDecimal userId){
        return cusUserCashAccountBiz.findUserCashAccount(userId);
    }

    /**
     * 获取用户绑定的账户列表
     * @param userId 用户ID
     * @return List<Map<String,Object>>
     */
    @RequestMapping("/findUserCashAccountList")
    public List<CusUserCashAccount> findUserCashAccountList(@RequestParam("userId") BigDecimal userId){
        return cusUserCashAccountBiz.find(" userId="+userId,null,null);
    }

    /**
     * 通过账户类型，查询提现账户
     * @param accountType 账户类型
     * @return Map<String,Object>
     */
    @RequestMapping("/findUserCashAccountByType")
    public CusUserCashAccount findUserCashAccountByType(@RequestParam("userId") BigDecimal userId,
                                                 @RequestParam("accountType") int accountType){
        return cusUserCashAccountBiz.findOne(" userId="+userId+" and accountType="+accountType,null);
    }
}
